package com.afd.ozblip.activity;

import com.afd.ozblip.entity.ActivityEntity;
import com.afd.ozblip.image.LoadImage;
import com.afd.ozblip.util.Constants;
import com.afd.ozblip.util.StringUtil;
import com.alibaba.fastjson.JSON;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class ActivityDetailActivity extends BaseActivity {

	/****************** 视图变量 **************************/
	private ImageView activityImg;
	private TextView activityTitle;
	private TextView activityEndTime;
	private TextView activityContent;

	/****************** 数据变量 **************************/
	private ActivityEntity activityInfo;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_detail);
		// 启动返回功能
		toBack();
		// 寻找视图
		findViews();
		// 设置监听
		setListeners();
		// 获取参数
		getBundle();
		// 设置视图
		setViews();
	}

	/**
	 * 寻找视图
	 */
	public void findViews() {
		this.activityImg = (ImageView) findViewById(R.id.iv_activity_item_image);
		this.activityTitle = (TextView) findViewById(R.id.tv_activity_item_title);
		this.activityEndTime = (TextView) findViewById(R.id.tv_activity_item_date);
		this.activityContent = (TextView) findViewById(R.id.tv_activity_item_content);
	}

	/**
	 * 设置监听
	 */
	public void setListeners() {
		View.OnClickListener moreClick = new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				switch (v.getId()) {
				case R.id.ll_more_layout_setting:
					Intent settingIntent = new Intent(
							ActivityDetailActivity.this, SettingActivity.class);
					startActivity(settingIntent);
					break;

				default:
					break;
				}
			}
		};
	}

	/**
	 * 获取传递的参数
	 */
	private void getBundle() {
		Intent intent = getIntent();
		activityInfo = (ActivityEntity) intent
				.getSerializableExtra("activityInfo");
	}

	private void setViews() {
		if (activityInfo != null) {
			// 活动图片
			String imageUrl = activityInfo.getActivityImageUrl();
			if (!StringUtil.isNullOrEmpty(imageUrl)) {
				LoadImage loadImage = new LoadImage(this);
				loadImage.addTask(Constants.WEB_IMAGE_PATH + imageUrl,
						activityImg);
			} else {
				activityImg.setImageDrawable(getResources().getDrawable(
						R.drawable.default_pic));
			}
			this.activityTitle.setText(activityInfo.getActivityTitle()); 
			this.activityEndTime.setText(activityInfo.getActivityEndTime()); 
			this.activityContent.setText(activityInfo.getActivityContent()); 
		}
	}
}